prices = [8, 1, 5, 3, 7, 4]
# prices = [7, 6, 4, 3, 1]
# max = prices[0]
"""
sel = []
一个个遍历，把所有情况得出在比较
for i in prices:
    for j in prices[i:1:1]:
        if prices[j] >= prices[i]:
            profit = prices[j] - prices[i]
            sel.append(profit)
max = sel[0]
for i in sel:
    if i >= max:
        max = i
print(max)
"""
pre = 0
max_profit = prices[0]

for i in range(1, len(prices)):
    pre = min(pre, prices[i-1])
    a = prices[i] - pre
    max_profit = max(max_profit, a)

print(max_profit)







